package br.rfpm.dominio;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import org.springframework.security.core.GrantedAuthority;

@Entity
@Table(catalog = "condominio", name = "authority")
public class Authority implements Serializable, GrantedAuthority {

	private static final long serialVersionUID = -793581660905277896L;

	public static final String ROLE_USER = "ROLE_USER";
	
	@Id
	@GenericGenerator(name = "increment-strategy", strategy = "increment", parameters = { @Parameter(name = "schema", value = "condominio") })
	@GeneratedValue(generator = "increment-strategy", strategy = GenerationType.TABLE)
	@Column(name = "ID_AUTHORITY")
	private Long id;

	@Column(name = "AUTHORITY")
	private String authority;
	
	public Authority() {
		super();
	}
	
	public Authority(String authority) {
		this.authority = authority;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setAuthority(String authority) {
		this.authority = authority;
	}

	@Override
	public String getAuthority() {
		return this.authority;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((authority == null) ? 0 : authority.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Authority other = (Authority) obj;
		if (authority == null) {
			if (other.authority != null)
				return false;
		} else if (!authority.equals(other.authority))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return this.authority;
	}
	
}
